package com.rdzn.mall.center.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.rdzn.mall.center.entity.OmsCartItem;
import com.rdzn.mall.center.mapper.OmsCartItemMapper;
import com.rdzn.mall.center.service.IOmsCartItemService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;
import java.util.List;

/**
 * @Description: oms_cart_item
 * @Author: jeecg-boot
 * @Date:   2020-08-27
 * @Version: V1.0
 */

@Service
public class OmsCartItemServiceImpl extends ServiceImpl<OmsCartItemMapper, OmsCartItem> implements IOmsCartItemService {


    @Override
    public OmsCartItem getOne(Integer productId, Integer memberId, Integer productSkuId) {
        return getOne(new LambdaQueryWrapper<OmsCartItem>().eq(OmsCartItem::getProductId, productId).eq(OmsCartItem::getMemberId, memberId).eq(OmsCartItem::getProductSkuId, productSkuId).eq(OmsCartItem::getDeleteStatus, 0));
    }

    @Override
    public List<OmsCartItem> list(Integer productId, Integer memberId) {
        return list(new LambdaQueryWrapper<OmsCartItem>().eq(OmsCartItem::getProductId, productId).eq(OmsCartItem::getMemberId, memberId).eq(OmsCartItem::getDeleteStatus, 0));
    }

    @Override
    public List<OmsCartItem> listByMemberId(Integer memberId) {
        return list(new LambdaQueryWrapper<OmsCartItem>().eq(OmsCartItem::getMemberId, memberId));
    }

    @Override
    public List<OmsCartItem> listChecked(Integer memberId) {
        return list(new LambdaQueryWrapper<OmsCartItem>().eq(OmsCartItem::getMemberId, memberId).eq(OmsCartItem::getIsChecked, 1).eq(OmsCartItem::getDeleteStatus, 0));
    }

    @Override
    public List<OmsCartItem> list(Integer memberId) {
        return list(new LambdaQueryWrapper<OmsCartItem>().eq(OmsCartItem::getDeleteStatus, 0).eq(OmsCartItem::getMemberId, memberId));
    }

    @Override
    public OmsCartItem update(OmsCartItem cartItem) {
        cartItem.setUpdateTime(new Date());
        updateById(cartItem);
        return cartItem;
    }

    @Override
    public boolean checked(List<Integer> ids, Integer isChecked) {
        OmsCartItem cartItem = new OmsCartItem();
        cartItem.setIsChecked(isChecked);
        return update(cartItem, new LambdaQueryWrapper<OmsCartItem>().in(OmsCartItem::getId, ids));
    }

    @Override
    public boolean delete(Integer memberId, List<Integer> ids) {
        OmsCartItem record = new OmsCartItem();
        record.setDeleteStatus(1);
        return update(record, new LambdaQueryWrapper<OmsCartItem>().eq(OmsCartItem::getMemberId, memberId).in(OmsCartItem::getId, ids));
    }

    @Override
    public boolean clear(Integer memberId) {
        OmsCartItem record = new OmsCartItem();
        record.setDeleteStatus(1);
        return update(record, new LambdaQueryWrapper<OmsCartItem>().eq(OmsCartItem::getMemberId, memberId));
    }

}
